﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>排产结果审核确认</title>
    <link rel="stylesheet" type="text/css" href="/InSiteWebApplication/Content/AnyGantt/css/anychart-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/InSiteWebApplication/Content/AnyGantt/fonts/css/anychart-font.min.css" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <style type="text/css">
        .anychart-credits
        {
            display: none;
        }
    </style>
</head>
<body>
    <div class="panelSection">
        <div class="easyui-panel " title="查询区域" style="padding: 3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <form id="searchForm" method="post" style="margin-bottom: 0;">
            <table>
                <tr class="divLabel">
                    <td>
                        订单号:
                    </td>
                    <td>
                        发动机号:
                    </td>
                    <td>
                        任务单号:
                    </td>
                    <td>
                        计划开始时间
                    </td>
                    <td>
                    </td>
                    <td>
                        计划结束时间
                    </td>
                    <td>
                    </td>
                    <td>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input id="txtMfgorderName" class="easyui-textbox" name="MfgorderName" type="text"
                            style="width: 120px; height: 22px" />
                    </td>
                    <td>
                        <input id="txtMachine" class="easyui-textbox" name="Machine" type="text" style="width: 120px;
                            height: 22px" />
                    </td>
                    <td>
                        <input id="txtContainerNo" class="easyui-textbox" name="ContainerNo" type="text"
                            style="width: 120px; height: 22px" />
                    </td>
                    <!--<td><input  type="hidden" name="MFGORDERID" style="width:150px; height:22px;display:none"  id="MFGORDERID"/><div id="mfgCombox"></div></td>
	    			<td><input class="easyui-combobox" type="text" name="ContainerNo" style="width: 170px; height: 22px" id="ContainerNo" data-options="multiple:true"/></td>-->
                    <td>
                        <input id="txtPlanStartTime" type="text" name="PlanStartTime" class="easyui-datebox"
                            style="width: 110px; height: 22px" />
                    </td>
                    <td>
                        -
                    </td>
                    <td>
                        <input id="txtPlanEndTime" type="text" name="PlanEndTime" class="easyui-datebox"
                            style="width: 110px; height: 22px" />
                    </td>
                    <td>
                        <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.searchData()">
                            查询</a>
                    </td>
                    <td>
                        <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.searchReset()">
                            重置</a>
                    </td>
                    <td>
                    </td>
                </tr>
            </table>
            </form>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="排产结果信息" style="padding: 3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div id="container">
            </div>
        </div>
    </div>
    <div class="panelSection">
        <div class="easyui-panel " title="按钮区域" style="padding: 3px;width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
            <div style="margin: 15px 0px">
                <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.examineAndconfirmApsResult()">确认审核</a>
                <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.returnApsResult()">退回</a>
            </div>
        </div>
    </div>
    <!--信息提示区域-->
    <div id="statusMessage" style="font-size: 14px; height: 40px">
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript" src="/InSiteWebApplication/Content/AnyGantt/zh-cn.js"></script>
<script type="text/javascript" src="/InSiteWebApplication/Content/AnyGantt/anychart-base.min.js"></script>
<script type="text/javascript" src="/InSiteWebApplication/Content/AnyGantt/anychart-ui.min.js"></script>
<script type="text/javascript" src="/InSiteWebApplication/Content/AnyGantt/anychart-exports.min.js"></script>
<script type="text/javascript" src="/InSiteWebApplication/Content/AnyGantt/anychart-gantt.min.js"></script>
<script type="text/javascript" src="/InSiteWebApplication/Content/AnyGantt/anychart-data-adapter.min.js"></script>
<script type="text/javascript">
    var page = {
        parentID:'',//父窗体div
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ApsHandler/ZSLimitedCapacityHandler.ashx",
        param: [], //需要查看的id
        comboxUrl:getRootPath() + "/Ashx/ZsHandler/ZSTestRunNoticeBillHandler.ashx",//combox下拉-调用后台的URL
        comboxAction:"GetMfgorder",//combox下拉-调用后台的具体方法
        //初始化页面
        init: function () {
            page.bind();
            page.loadInfiniteCapacity();
        },
        bind:function(){},
        treeData:null,
        returnData:null,
        ContainerData:null,//任务单数据
        recountApsData:function(parentId,itemId,differ){
            page.returnData.forEach(item=>{
                if(item.id==parentId)//批次级计划
                {
                    let start=dayjs(item.periods[0].start).add(differ,'ms').format("YYYY/MM/DD HH:mm:ss");
                    let end=dayjs(item.periods[0].end).add(differ,'ms').format("YYYY/MM/DD HH:mm:ss");

                    item.periods[0].start=start;
                    item.periods[0].end=end;
                    item.customData.differ=differ;
                    item.customData.constarttime=start;
                    item.customData.conendtime=end;
                    //更新treeData
                    var treeItem= page.treeData.filter(_treeItem=>{
                        return _treeItem.get('id')==item.id;
                    });
                    if(treeItem!=null){
                    
                       var prePeriods=treeItem[0].get('periods');
                       prePeriods[0].start=item.periods[0].start;
                       prePeriods[0].end=item.periods[0].end;
                       treeItem[0].set('periods',prePeriods);
                       treeItem[0].get('customData').differ=differ;

                       console.log(treeItem);
                    }                    

                }else if(item.parent==parentId)//工序级计划
                {
                    item.periods[0].start=dayjs(item.periods[0].start).add(differ,'ms').format("YYYY/MM/DD HH:mm:ss");
                    item.periods[0].end=dayjs(item.periods[0].end).add(differ,'ms').format("YYYY/MM/DD HH:mm:ss");

                    //更新treeData
                    var treeItem= page.treeData.filter(_treeItem=>{
                        return _treeItem.get('id')==item.id;
                    });                     
                    if(treeItem!=null){

                       var prePeriods=treeItem[0].get('periods');
                       prePeriods[0].start=item.periods[0].start;
                       prePeriods[0].end=item.periods[0].end;
                       treeItem[0].set('periods',prePeriods);

                    }
                }
            });

        },
        drawingFunction:function () {
              // get the shapes of the element
              var shapes = this["shapes"];
              // get the shape to be modified
              var path = shapes["path"];
              // get the bounds of the element
              var bounds = this["predictedBounds"];
    
            //this["period"];//当前渲染的块
            var item=this["item"];
            if(item.numChildren()>0){
               // console.log(this.period); 
                //path.fill('green');   
            }


             // console.log(this["predictedBounds"]);

              var h = bounds.height;
              var t = bounds.top;
              var l = bounds.left;
              var r = l + bounds.width;
              var h1 = t + h;   
  
            let period=this['period'];
            let customData=period.customData;
            if(customData!=null){

            //console.log(customData);

            if(customData.isHolidate!=null){

            h1+=4;
            t-=3;
            path.fill('#ccc');   
            //console.log(this['period']);

            }

            }
   
              //var h4 = h/4;
              //var h2 = h/2;

              // draw a rounded rectangle
            //  path.moveTo(l + h4, h1 - h4)
            //  path.arcTo(h4,h4, -270, 180)
            //  path.lineTo(r - h4, t + h4)
            //  path.arcTo(h4, h4, -90, 180)
            //  path.lineTo(l + h2, h1 - h4)
            //  path.close(); 

              path.moveTo(l, t);
              path.lineTo(l , h1 );
              path.lineTo(r, h1);
              path.lineTo(r, t);

              //console.log(path.domElement());

              path.close(); 


},
        //确认审核操作
        examineAndconfirmApsResult:function(){
            var ContainerData=page.ContainerData.filter(i=>{return i.isCheck==1});
            if(ContainerData==null||ContainerData.length==0){displayMessage("请选择数据再进行操作",false); return;}
             var param = {
                    action: "examineAndconfirmApsResult",
                    data:JSON.stringify(ContainerData)
                }
             page.post(param, function (res) {
                page.loadInfiniteCapacity();
                displayMessage(res.Message, res.Result);
            });
        },
        //结果退回操作
        returnApsResult:function(){
            var ContainerData=page.ContainerData.filter(i=>{return i.isCheck==1});
            if(ContainerData==null||ContainerData.length==0){displayMessage("请选择数据再进行操作",false); return;}
             var param = {
                    action: "confirmAdjustedResult",
                    data:JSON.stringify(ContainerData),
                    status:'0'
                }
             page.post(param, function (res) {
                page.loadInfiniteCapacity();
                displayMessage(res.Message, res.Result);
            });
        },        
        searchReset:function(){
            page.reset(true,true,false);
        },
        searchData:function(){
            page.reset(false,true,false);
            var ContainerNo= $('#txtContainerNo').textbox('getValue');
            var PlanStartTime= $("#txtPlanStartTime").datebox('getValue');            
            var PlanEndTime= $("#txtPlanEndTime").datebox('getValue');    
            page.param=ContainerNo;
            page.loadInfiniteCapacity();
        },
        loadInfiniteCapacity:function(){
            var para={
                action:"getStepInfiniteAps",
                machine:$('#txtMachine').textbox('getValue'),
                containerNo:$('#txtContainerNo').textbox('getValue'),
                mfgorderName:$('#txtMfgorderName').textbox('getValue'),
                planStartTime:$("#txtPlanStartTime").datebox('getValue'),
                planEndTime:$("#txtPlanEndTime").datebox('getValue'),
                status:2};
            page.post(para,function(result){
                if(result.Result){
                    page.ContainerData=result.DBTable;
                    page.loadAnychart(JSON.parse(result.ReturnData));
                }else{
                    $('#container').empty();
                    displayMessage(result.Message, false);
                }
            });

        },

        loadAnychart: function (ReturnData) { //无限产能加载方法
            $('#container').empty();
            anychart.onDocumentReady(function () {

//                anychart.data.loadJsonFile(page.ajaxUrl + "?action=getStepInfiniteAps&param="+page.param.join(',')+"&mfgorderName="+$('#txtCombox').textbox('getValue')+"&planStartTime="+$("#txtPlanStartTime").datebox('getValue')+"&planEndTime="+$("#txtPlanEndTime").datebox('getValue')+"&status=2", function (result) {
                //anychart.data.loadJsonFile(page.ajaxUrl + "?action=getStepInfiniteAps&machine="+$('#txtMachine').textbox('getValue')+"&containerNo="+$('#txtContainerNo').textbox('getValue')+"&mfgorderName="+$('#txtMfgorderName').textbox('getValue')+"&planStartTime="+$("#txtPlanStartTime").datebox('getValue')+"&planEndTime="+$("#txtPlanEndTime").datebox('getValue')+"&status=2", function (result) {

                    anychart.format.outputLocale('zh-cn');
                    //anychart.format.outputDateTimeFormat('yyyy-MM-dd');
                    anychart.format.inputDateTimeFormat("yyyy/MM/dd HH:mm:ss");

//                    if(result.Result==false){
//                        displayMessage(result.Message, false);
//                        return;
//                    }

                    var data=ReturnData;
                    page.returnData=ReturnData;
                    //page.ContainerData=result.DBTable;
                    //console.log(data);

                    // create data tree on raw data
                    var treeData = anychart.data.tree(data, 'as-table');

                    page.treeData=treeData;
                    // create resource gantt chart
                    chart = anychart.ganttResource();

                    chart.splitterPosition(400); //左边grid宽度

                    // set data for the chart
                    chart.data(treeData);

                    //设置列
                    var dataGrid = chart.dataGrid();
                    dataGrid.column(0)
                            .title('序号')
                            .width(30)
                            .cellTextSettings({ hAlign: 'center' });

                    dataGrid.column(1)
                            .title("任务")
                            .cellTextSettingsOverrider(page.labelTextSettingsOverrider)
                            .cellTextSettings({ hAlign: 'left', width: 180 });

                    dataGrid.column(2)
                            .title("开始时间")
                            .cellTextSettings({ hAlign: 'left', width: 100 })
                            .format(item=>{
                                let customData=item.get("customData");                                
                                if(customData!=null)
                                 {
                                    return customData.constarttime;
                                  }
                                  else{
                                      var _periods=item.get('periods');
                                     var gridEnd="";
                                     _periods.forEach(function(i){
                                        gridEnd+=i.end.substr(0,i.start.lastIndexOf(":"))+ "\r\n";
                                     });
                                     return  gridEnd;
                                  }
                            });
                    dataGrid.column(3)
                            .title("结束时间")
                            .cellTextSettings({ hAlign: 'left', width: 100 })
                            .format(item=>{
                                 let customData=item.get("customData");                                 
                                 if(customData!=null)
                                 {
                                    return customData.conendtime;
                                  }
                                  else{
                                      var _periods=item.get('periods');
                                     var gridEnd="";
                                     _periods.forEach(function(i){
                                        gridEnd+=i.end.substr(0,i.end.lastIndexOf(":"))+ "\r\n";
                                     });
                                     return gridEnd;
                                  }
                               
                            });
                     dataGrid.column(4)
                            .title("工位")
                            .cellTextSettings({ hAlign: 'left', width: 100 })
                            .format(item=>{
                                 let customData=item.get("customData");
                                 if(customData==null)
                                 {
                                     var _periods=item.get('periods');
                                     var gridEnd="";
                                     _periods.forEach(function(i){
                                        gridEnd+=i.workstation+ "\r\n";
                                     });
                                     return gridEnd;
                                  }
                            });
                     //datagrid tooltips
                    dataGrid.tooltip().useHtml(true); 
                   

                    var periods = chart.getTimeline().periods();

                    // set the height of periods
                    //periods.height(40);
                    // draw custom periods
                    periods.rendering().drawer(page.drawingFunction);

                    //图形块的label
                    var periodLabels =periods.labels();
                    periodLabels.enabled(true);
                    periodLabels.useHtml(true);
                    periodLabels.fontColor("#104d89");
                    periodLabels.fontWeight(600);
                    periodLabels.format(function() {
                        let customData=this.period.customData;
                        if(customData!=null){
                            if(customData.isHolidate!=null&&customData.isHolidate=='1'){
                                var text='<span style="color:#fff;font-wieght:bold">'+this.period.text+'</span>';
                                return text;     
                            }
                        }
                    });

                    // configure tooltips of the timeline
                chart.getTimeline().tooltip().useHtml(true);
                chart.getTimeline().tooltip().format(function() {

                      var period=this.period;
                      var numChildren = this.item.numChildren();

                      var startDate = anychart.format.dateTime(this.start, "yyyy-MM-dd HH:mm:ss");
                      var endDate = anychart.format.dateTime(this.end, "yyyy-MM-dd HH:mm:ss");


                      var parentText ="<span style='font-weight:600;font-size:12pt'>" + 
                                     '开始:'+startDate + "<br>"+
                                     '结束:'+endDate+"</span>"

                      var childText ="<span style='font-weight:600;font-size:12pt'>" + 
                                     '开始:'+startDate + "<br>"+
                                     '结束:'+endDate+"</span>"

                     
                      // identify the resource type and display the corresponding text
                      if (numChildren > 0) {
                        //console.log(this.item.getChildAt(0).get('periods'));
                        return parentText;
                      } else {
                        //console.log(this.item.get('periods'));
                        return childText;
                      }

                });

                    // make chart editable
                    //chart.editing(true);
                    chart.getTimeline().edit(false);

                    chart.contextMenu(false);//禁用右键

                    // set container id for the chart
                    chart.container('container');

                    // initiate chart drawing
                    chart.draw();
                                       
                    // zoom chart all dates range
                    chart.fitAll();

                    // Enable chart redrawing.
                    chart.autoRedraw(true);
                    //var header = chart.getTimeline().header();//设置时间线表头背景色
                    //    header.fill("#64b5f6 0.2");                  

                    //事件绑定
                    chart.listen('rowClick', function (e) {
                        var item=e['item'];
                        var allChildItems=item.getChildren();
                        if(allChildItems==null||allChildItems.length==0){
                                return;
                            }else{
                                 //dataGrid.rowSelectedFill("#ffd54f 0.3");//选中行表格背景样式
                            
                            var preItem=page.returnData.find(i=>{return i.id==item.get('id')}) ;//调整之前的值
                            var container=page.returnData.filter(i=>{return i.containerid==preItem.containerid});//筛选相同批次的数据
                            $.each(container,function(index,itemm){
                                if(itemm.id==item.get('id')){
                                    itemm.customData.differ=itemm.customData.differ==1?0:1;
                                }else{
                                    itemm.customData.differ=0;
                                }
                                 var containerv=page.ContainerData.find(i=>{return i.APSPLANINFOID==itemm.id});
                                    containerv.isCheck=itemm.customData.differ;
                            });
                            page.loadAnychart(page.returnData);
                        }
                        //var itemName = e.item.get("name");
                        
                    });
                   
                //});
            });
        },
        labelTextSettingsOverrider:function(label, item) {
            //console.info(item.get("customData"));
            if(item.get("customData")!=undefined){
                if(item.get("customData").differ==1){
                    label.fontColor('blue');     
                }
            }

            var _periods=item.get('periods');               
            _periods.forEach(function(i){
            if(i.showcolor=="1")
            {
                label.fontColor('red');                    
            }

            if(i.showcolor=="2")
            {
                label.fontColor('yellow');                    
            }
            });           
        } ,
    
        //post数据
        post: function (param, callback) {
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        },
          //清除方法，重要！！！
    reset: function (iscondition, isresult, isDetail) {
        clearMessage();
        if (iscondition) {            
            $("#txtPlanStartTime").textbox("setValue", ""); 
            $("#txtPlanEndTime").textbox("setValue", ""); 
            $("#txtMfgorderName").textbox("setValue", ""); 
            $("#txtMachine").textbox("setValue", ""); 
            $("#txtContainerNo").textbox("setValue", ""); 
        }

        if (isresult) {
           $("#container").empty();
        }
    }
   }

$(function () {
    //获取传参
    page.parentID = getParam("parentDiv");
    page.param=[];//parent.$("#" + page.parentID).dialog('options').popupData;
    page.init();

});
</script>
<script src="/InSiteWebApplication/Scripts/ZsJs/selectCombox.js" type="text/javascript"></script>
